package com.redside.model;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * This class represents the initial complaint object that represents a
 * complaint that is not yet associated with a business.
 * 
 * @author <a href="mailto:pchapman@redsidesoftware.com">Peter Chapman</a>
 */

@Entity
@Table(name = "initial_complaint")
public class InitialComplaint extends BaseObject implements Serializable {

    private static final long serialVersionUID = 3868047798480811864L;

    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;
    
    @Column(name="bus_cat_id")
    private Long businessCategoryId;    
    
    @Embedded
    private Address address = new Address();
    
    @Column(name="business_name",nullable=false,length=50)
    private String businessName;
    
    @Column(name="business_phone",length=14)
    private String businessPhone;
    
    @Column(name="business_phone_ext",length=6)
    private String businessPhoneExt;
    
    @Column(name="complainant_name", length=50)
    private String complainantName;
    
    @Column(name="complainant_address", length=50)
    private String complainantAddress;
    
    @Column(name="complainant_city", length=50)
    private String complainantCity;
    
    @Column(name = "complainant_state_id", length = 32)
    private String complainantStateId;
    
    @Column(name="complainant_zip",length=5)
    private String complainantZip;
    
    @Column(name="complainant_phone", length=12)
    private String complainantPhone;
    
    @Column(name="complainant_phone_ext", length=6)
    private String complainantPhoneExt;
    
    @Column(name="complainant_email")
    private String complainantEmail;
    
    @Column(name="anonymous",nullable=false)
    private boolean anonymous;
    
    @OneToMany(mappedBy="initialComplaint", cascade=CascadeType.ALL)
    @JoinColumn(name = "complaint_id")
    private List<Complaint> complaints = new ArrayList<Complaint>();

    
    /**
	 * 
	 */
	public InitialComplaint() {
		super();
	}

	/**
	 * @param businessCatLkp
	 * @param countyLkp
	 * @param stateLkp
	 * @param businessName
	 * @param businessAddress1
	 * @param businessCity
	 * @param businessZip
	 * @param businessPhone
	 * @param anonymous
	 */
	public InitialComplaint(Long businessCategoryId, String countyId,
			String stateId, String businessName, String businessAddress1,
			String businessCity, String businessZip, String businessPhone,
			boolean anonymous) {
		super();
		this.businessCategoryId = businessCategoryId;
		this.address.setCountyId(countyId);
        this.address.setStateId(stateId);
		this.businessName = businessName;
		this.address.setAddress1(businessAddress1);
		this.address.setCity(businessCity);
		this.address.setPostalCode(businessZip);
		this.businessPhone = businessPhone;
		this.anonymous = anonymous;
	}

	/**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
	 * @return the businessCategoryId
	 */
	public Long getBusinessCategoryId() {
		return businessCategoryId;
	}

	/**
	 * @param businessCategoryId the businessCategoryId to set
	 */
	public void setBusinessCategoryId(Long businessCategoryId) {
		this.businessCategoryId = businessCategoryId;
	}

	/**
     * @return the businessName
     */
    public String getBusinessName() {
        return businessName;
    }

    /**
     * @param businessName the businessName to set
     */
    public void setBusinessName(String businessName) {
        this.businessName = businessName;
    }

    /**
	 * @return the address
	 */
	public Address getAddress() {
		return address;
	}

	/**
	 * @param address the address to set
	 */
	public void setAddress(Address address) {
		this.address = address;
	}

	/**
     * @return the businessPhone
     */
    public String getBusinessPhone() {
        return businessPhone;
    }

    /**
     * @param businessPhone the businessPhone to set
     */
    public void setBusinessPhone(String businessPhone) {
        this.businessPhone = businessPhone;
    }

    /**
     * @return the businessPhoneExt
     */
    public String getBusinessPhoneExt() {
        return businessPhoneExt;
    }

    /**
     * @param businessPhoneExt the businessPhoneExt to set
     */
    public void setBusinessPhoneExt(String businessPhoneExt) {
        this.businessPhoneExt = businessPhoneExt;
    }

    /**
     * @return the complainantName
     */
    public String getComplainantName() {
        return complainantName;
    }

    /**
     * @param complainantName the complainantName to set
     */
    public void setComplainantName(String complainantName) {
        this.complainantName = complainantName;
    }

	/**
	 * @return the complainantAddress
	 */
	public String getComplainantAddress() {
		return complainantAddress;
	}

	/**
	 * @param complainantAddress the complainantAddress to set
	 */
	public void setComplainantAddress(String complainantAddress) {
		this.complainantAddress = complainantAddress;
	}

	/**
	 * @return the complainantCity
	 */
	public String getComplainantCity() {
		return complainantCity;
	}

	/**
	 * @param complainantCity the complainantCity to set
	 */
	public void setComplainantCity(String complainantCity) {
		this.complainantCity = complainantCity;
	}

	/**
	 * @return the complainantStateId
	 */
	public String getComplainantStateId() {
		return complainantStateId;
	}

	/**
	 * @param complainantStateId the complainantStateId to set
	 */
	public void setComplainantStateId(String complainantStateId) {
		this.complainantStateId = complainantStateId;
	}

	/**
	 * @return the complainantZip
	 */
	public String getComplainantZip() {
		return complainantZip;
	}

	/**
	 * @param complainantZip the complainantZip to set
	 */
	public void setComplainantZip(String complainantZip) {
		this.complainantZip = complainantZip;
	}

	/**
     * @return the complainantPhone
     */
    public String getComplainantPhone() {
        return complainantPhone;
    }

    /**
     * @param complainantPhone the complainantPhone to set
     */
    public void setComplainantPhone(String complainantPhone) {
        this.complainantPhone = complainantPhone;
    }

    /**
     * @return the complainantPhoneExt
     */
    public String getComplainantPhoneExt() {
        return complainantPhoneExt;
    }

    /**
     * @param complainantPhoneExt the complainantPhoneExt to set
     */
    public void setComplainantPhoneExt(String complainantPhoneExt) {
        this.complainantPhoneExt = complainantPhoneExt;
    }

    /**
     * @return the complainantEmail
     */
    public String getComplainantEmail() {
        return complainantEmail;
    }

    /**
     * @param complainantEmail the complainantEmail to set
     */
    public void setComplainantEmail(String complainantEmail) {
        this.complainantEmail = complainantEmail;
    }

    /**
     * @return the anonymous
     */
    public boolean isAnonymous() {
        return anonymous;
    }

    /**
     * @param anonymous the anonymous to set
     */
    public void setAnonymous(boolean anonymous) {
        this.anonymous = anonymous;
    }

    /**
     * @return the complaints
     */
    public List<Complaint> getComplaints() {
        return complaints;
    }

    /**
     * @param complaints the complaints to set
     */
    public void setComplaints(List<Complaint> complaints) {
        this.complaints = complaints;
    }
    
    public void addComplaint(Complaint complaint) {
        List<Complaint> complaints = this.getComplaints();
        if (complaints == null) {
            complaints = new ArrayList<Complaint>();
        }
        complaints.add(complaint);
        this.setComplaints(complaints);
    }

	/**
	 * @see java.lang.Object#equals(Object)
	 */
	public boolean equals(Object object) {
		if (!(object instanceof InitialComplaint)) {
			return false;
		}
		InitialComplaint rhs = (InitialComplaint) object;
		return new EqualsBuilder().append(
				this.businessName, rhs.businessName).append(this.businessPhone,
				rhs.businessPhone).append(this.complainantAddress,
				rhs.complainantAddress).append(this.complaints, rhs.complaints)
				.append(this.complainantPhone, rhs.complainantPhone)
				.append(this.complainantPhoneExt, rhs.complainantPhoneExt)
				.append(this.address, rhs.address).append(this.complainantName,
						rhs.complainantName).append(this.businessPhoneExt,
						rhs.businessPhoneExt).append(this.complainantEmail,
						rhs.complainantEmail).append(this.complainantZip,
						rhs.complainantZip).append(this.complainantCity,
						rhs.complainantCity).isEquals();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
    public int hashCode() {
        return new HashCodeBuilder(88129721, 90615669).append(this.complainantStateId)
                .append(this.businessName).append(
                        this.businessPhone).append(this.complainantAddress).append(
                        this.complainantPhone).append(
                        this.anonymous).append(this.id).append(this.businessCategoryId)
                .append(this.complainantPhoneExt).append(
                        this.complainantName).append(this.businessPhoneExt)
                        .append(this.complainantEmail).append(
                        this.complainantZip).append(
                        this.complainantCity).toHashCode();
    }

	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this).append("complainantCity",
				this.complainantCity).append("complainantName",
				this.complainantName).append("complainantAddress",
				this.complainantAddress).append("complaints", this.complaints)
				.append("anonymous", this.anonymous).append("complainantPhone",
						this.complainantPhone).append("complainantZip",
						this.complainantZip).append("businessCategoryId",
						this.businessCategoryId).append("businessName",
						this.businessName).append("complainantStateId",
						this.complainantStateId).append("complainantPhoneExt",
						this.complainantPhoneExt).append("businessPhone",
						this.businessPhone).append("businessPhoneExt",
						this.businessPhoneExt).append("complainantEmail",
						this.complainantEmail).append("id", this.id).append(
						"address", this.address).toString();
	}

	
}